package com.platform.mobile.dao.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.stereotype.Repository;

import com.platform.common.dao.impl.CommonDaoImpl;
import com.platform.mobile.dao.MLoginDao;
import com.platform.mobile.entity.VisitAccount;
import com.platform.mobile.entity.VisitUser;
import com.platform.tool.HelpFunctions;

@Repository
public class MLoginDaoImpl extends CommonDaoImpl implements MLoginDao{

	@SuppressWarnings("unchecked")
	@Override
	public boolean checkUserInfo(String login_name) {
		
		List<VisitAccount> list = new ArrayList<VisitAccount>();
		
		StringBuilder whereSql = new StringBuilder("from VisitAccount where 1=1 ");
		List<Object> params = new ArrayList<Object>();
		
		params.add(login_name);
		whereSql.append("and login_name = ?");
		
		list = (List<VisitAccount>) getListByHQL(whereSql.toString(),params.toArray(),
				null);
		
		if(!HelpFunctions.isEmpty(list))
			return true;
		else
			return false;
	}

	@SuppressWarnings("unchecked")
	@Override
	public VisitUser getVisitUser(String login_name) {
		
		List<VisitUser> list = new ArrayList<VisitUser>();
		
		StringBuilder whereSql = new StringBuilder("from VisitUser where 1=1 ");
		List<Object> params = new ArrayList<Object>();
		
		params.add(login_name);
		whereSql.append("and login_name = ?");
		
		list = (List<VisitUser>) getListByHQL(whereSql.toString(),params.toArray(),
				null);
		
		if(!HelpFunctions.isEmpty(list)){
			return list.get(0);
		}
		
		return null;
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<VisitUser> getVisitUserByAssitantId(String assitant_id) {
		
		List<VisitUser> resultList = new ArrayList<VisitUser>();
		List<Object[]> list = new ArrayList<Object[]>();
		
		StringBuilder whereSql = new StringBuilder(
				"SELECT u.* FROM assitant a "
				+ "LEFT JOIN visit_user u "
				+ "ON u.ID = a.u_id "
				+ "WHERE a_id = ? ");
		
		List<Object> params = new ArrayList<Object>();
		params.add(assitant_id);
		
		list = (List<Object[]>) getListBySQL(whereSql.toString(), params.toArray(), null, null);
		
		if(!HelpFunctions.isEmpty(list)){
			for(Object[] objArray : list){
				VisitUser vu = new VisitUser();
				if(objArray[0] != null){
					vu.setId((Integer)objArray[0]);
				}
				
				if(objArray[1] != null){
					vu.setReal_name(objArray[1].toString());
				}
				
				if(objArray[2] != null){
					vu.setSex(objArray[2].toString());
				}
				
				if(objArray[3] != null){
					vu.setStatus(objArray[3].toString());
				}
				
				if(objArray[4] != null){
					vu.setUser_type(objArray[4].toString());
				}
				
				if(objArray[5] != null){
					vu.setLogin_name(objArray[5].toString());
				}
				
				if(objArray[6] != null){
					vu.setThumb(objArray[6].toString());
				}
				
				if(objArray[7] != null){
					vu.setPost(objArray[7].toString());
				}
				
				if(objArray[8] != null){
					vu.setMajor(objArray[8].toString());
				}
				
				if(objArray[9] != null){
					vu.setDocDesc(objArray[9].toString());
				}
				
				if(objArray[10] != null){
					vu.setWork_unit_phone(objArray[10].toString());
				}
				
				if(objArray[11] != null){
					vu.setQualifiedThumb(objArray[11].toString());
				}
				
				if(objArray[12] != null){
					vu.setSpeciality(objArray[12].toString());
				}
				
				if(objArray[13] != null){
					vu.setAge((int)objArray[13]);
				}
				
				if(objArray[14] != null){
					vu.setEducation(objArray[14].toString());
				}
				
				if(objArray[15] != null){
					vu.setDept_id((int)objArray[15]);
				}
				
				if(objArray[16] != null){
					vu.setPhone(objArray[16].toString());
				}
				
				if(objArray[17] != null){
					vu.setBirthday(objArray[17].toString());
				}
				
				if(objArray[18] != null){
					vu.setAddress(objArray[18].toString());
				}
				
				if(objArray[19] != null){
					vu.setId_card_no(objArray[19].toString());
				}
				
				if(objArray[20] != null){
					vu.setBirthplace(objArray[20].toString());
				}
				
				if(objArray[21] != null){
					vu.setNation(objArray[21].toString());
				}
				
/*				if(objArray[22] != null){
					vu.setMarriage((byte)objArray[22]);
				}*/
				
				if(objArray[23] != null){
					vu.setGoal(objArray[23].toString());
				}
				
				if(objArray[24] != null){
					vu.setRemark(objArray[24].toString());
				}
				
				if(objArray[25] != null){
					vu.setChannel_id(objArray[25].toString());
				}
				
				if(objArray[26] != null){
					vu.setLast_update_date(objArray[26].toString());
				}
				
				if(objArray[27] != null){
					vu.setOrg_id((int)objArray[27]);
				}
				
				if(objArray[28] != null){
					vu.setCert_status(objArray[28].toString());
				}
				
				if(objArray[29] != null){
					vu.setVisit_time(objArray[29].toString());
				}
				
				resultList.add(vu);
			}
		}
		
		return resultList;
	}


}
